package com.pubinfo.passbook.common.service.master.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pubinfo.passbook.common.entity.TRuleRole;
import com.pubinfo.passbook.common.entity.TRuleUser;
import com.pubinfo.passbook.common.mapper.TRuleRoleMapper;
import com.pubinfo.passbook.common.mapper.TRuleUserMapper;
import com.pubinfo.passbook.common.model.dto.rule.RuleUserParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.service.master.TRuleRoleService;
import com.pubinfo.passbook.common.service.master.TRuleUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Service
@Slf4j
public class TRuleUserServiceImpl extends ServiceImpl<TRuleUserMapper, TRuleUser>
    implements TRuleUserService {
  
  @Resource
  private TRuleRoleMapper roleMapper;
  
  @Override
  public IPage<TRuleUser> selectRuleUser(RuleUserParam param) {
    IPage<TRuleUser> iPage = page(param.getPage("create_time"));
    return this.baseMapper.selectRuleUser(iPage, param);
  }
  
  @Override
  public JsonResult<String> saveRuleUser(TRuleUser ruleUser) {
    TRuleRole tRuleRole = roleMapper.selectById(ruleUser.getRoleId());
    if (tRuleRole == null)
      return JsonResult.error("规则角色id不存在");
    this.baseMapper.insert(ruleUser);
    return JsonResult.success("新增成功");
  }
  
  @Override
  public JsonResult<String> updateRuleUser(TRuleUser ruleUser) {
    TRuleRole tRuleRole = roleMapper.selectById(ruleUser.getRoleId());
    if (tRuleRole == null)
      return JsonResult.error("规则角色id不存在");
    this.baseMapper.updateById(ruleUser);
    return JsonResult.success("更新成功");
  }
}




